﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using SqlMapper.Serializers;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace NoteHelper.Test.Xml
{
    [TestClass]
    public class XmlToEntity
    {
        private static log4net.ILog logger;

        [ClassInitialize]
        public static void InitLog(TestContext tc)
        {
            var configFile = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CfgFiles\\log4net.cfg.xml");
            log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(configFile));
            logger = log4net.LogManager.GetLogger(typeof(XmlToEntity));

            logger.Debug("init log4net");
        }

        [TestMethod]
        public void SelectDeSerializerTest()
        {
            string resource = "CfgFiles/SqlMappers.config";
            var doc = new XmlDocument();
            string _applicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
            doc.Load(Path.Combine(_applicationBase, resource));
            Assert.IsNotNull(doc);
            
            //XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
            //nsmgr.AddNamespace("abcdefg", "NoteHelper.Test");
            XmlNodeList nodes = doc.GetElementsByTagName("select");
            Assert.AreEqual(1, nodes.Count);

            var node = nodes[0];
            var select = SelectDeSerializer.Deserialize(nodes[0]);
            logger.Debug(select.Id);
            logger.Debug(select.Sql);
        }
    }
}
